/**
 * Created by mooshroom on 2017/8/10.
 */
var webpack=require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin');

var webpack_config={
    devtool: "source-map",//配置生成 Source Maps 的选项
    entry:{},//入口文件路径
    output:{
        path: __dirname+'/dist/',
        filename: "js/[name].js",
        // chunkFilename: "[id].chunk.js"
    },
    devServer: {
        contentBase: "./public",
        port: '8080',
        inline: true,
        historyApiFallback: true
    },
    module: {
        loaders: [
            {
                test: /\.json$/,
                loader: 'json-loader'
            },
            {
                test: /\.css$/,
                loader: ['style-loader','css-loader'] //添加对样式表的处理,感叹号的作用在于使同一文件能够使用不同类型的 loader
            },
            {
                test: /\.((woff2?|svg|eot|ttf)(\?v=[0-9]\.[0-9]\.[0-9]))|(woff2?|svg|jpe?g|png|gif|ico)|(eot|ttf)$/,
                loaders: [
                    // 小于10KB的图片会自动转成dataUrl]
                    'url-loader?limit=10240&name=img/[hash:8].[name].[ext]',
                    'image-webpack-loader?{bypassOnDebug:true, progressive:true,optimizationLevel:3,pngquant:{quality:"65-80",speed:4}}'
                ]
            },
            {
                test: /\.(htm|html)$/,
                loader: 'html-withimg-loader'
            },
            {
                test:/\.md$/,
                loader:'markdown-loader?{breaks:true}',
            }
        ]
    },
    plugins:[
        // new HtmlWebpackPlugin({
        //     template: __dirname + "/app/index.tmpl.html"
        // })
    ],
    resolve: {
        extensions: ['.js'],
        alias: {
            avalon: './src/js/avalon.modern',//在正常情况下我们以CommonJS风格引用avalon,以require('avalon')
        }
    }
}

//扫描模块并植入到配置中
var nav=require('./nav.json')
var StringFormat=require('./src/js/stringFormat.js').StringFormat
// var layout=require('./app/layout/layout.js')
// console.log(layout)

nav.forEach(function (el, i, arr) {
    // console.log(el)
    webpack_config.entry[el.name]=StringFormat('./app/pages/{{name}}/entry.js',el)

    webpack_config.plugins.push(
        new HtmlWebpackPlugin({
            template: StringFormat('html-withimg-loader!./app/pages/{{name}}/page.html',el),
            filename:  el.name+'.html',
            title:el.title,
            chunks:[el.name],
        })
    )
})

console.log(webpack_config)
module.exports = webpack_config


